package com.lz.wsy.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lz.security.pojo.LoginUser;
import com.lz.security.utils.SecurityUtil;
import com.lz.wsy.mapper.NoticeMapper;
import com.lz.wsy.pojo.Notice;
import com.lz.wsy.service.NoticeService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.Date;

/**
 * @description 公告Service实现
 */
@Service
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice>
        implements NoticeService {

    @Override
    public Notice get(Integer noticeId) {
        return baseMapper.selectById(noticeId);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean addAndEdit(Notice notice) {
        //获取登陆用户信息
        /*LoginUser loginuser = SecurityUtil.getLoginuser();
        notice.setCreateUser(loginuser.getUsername());
        notice.setUpdateUser(loginuser.getUsername());*/
        notice.setUpdateTime(new Date());
        if(null == notice.getNoticeId()){
            notice.setCreateTime(new Date());
            baseMapper.insert(notice);
        }else {
            baseMapper.updateById(notice);
        }
        return true;
    }
}




